﻿using AutoMapper.Features;
using Ebusiness_Application_Contracts.Dto.Feature;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
using Volo.Abp.FeatureManagement;
using Volo.Abp.MultiTenancy;

namespace Ebusiness_Application.Service
{
    /// <summary>
    /// 特征服务
    /// </summary>
    [Dependency(ServiceLifetime.Transient)]
    public class FeatureService : IFeatureService, IRemoteService
    {
        public ICurrentTenant currentTenant { get; set; }

        public IFeatureManager featureManager { get; set; }

        /// <summary>
        /// 单个给租户添加商品特征
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<string> SetTenancyFeature(string key, string tenancyVal)
        {
            await featureManager.SetForTenantAsync((Guid)currentTenant.GetId(), key, tenancyVal);
            return "添加成功";
        }

        /// <summary>
        /// 批量给租户添加商品特征
        /// </summary>
        /// <param name="featureInsertDtos"></param>
        /// <returns></returns>
        public async Task<string> SetTenancyFeatureList(List<FeatureInsertDto> featureInsertDtos)
        {
            foreach (var feature in featureInsertDtos)
            {
                await featureManager.SetForTenantAsync((Guid)currentTenant.GetId(), feature.Name, feature.tenancyVal);
            }
            return "添加成功";
        }

        /// <summary>
        /// 设置租户添加商品特征
        /// </summary>
        /// <param name="key"></param>
        /// <param name="tenancyVal"></param>
        /// <returns></returns>
        public async Task<string> SetTenancyAddProducrGroupFeature(string tenancyVal)
        {
            await featureManager.SetForTenantAsync((Guid)currentTenant.GetId(), "AddProducrGroupFeature", tenancyVal);
            return "添加成功";
        }
    }
}
